package com.jinpeng.rabbitmq.direct;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author JINPENG
 * @Todo   直连型交换机
 *
 */
@Configuration
public class DirectRabbitConfig {

    /**
     * 注册队列 directQueue
     * @return
     */
    @Bean
    public Queue directQueue() {
        //true 是否持久
        return new Queue("directQueue",true);
    }

    /**
     * 注册交换机 directExchange
     * @return
     */
    @Bean
    DirectExchange directExchange() {
        return new DirectExchange("directExchange");
    }


    /**
     * 绑定  将队列和交换机绑定, 并设置用于匹配键：directRouting
     */
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("directRouting");
    }

    @Bean
    DirectExchange noQueueExchange() {
        return new DirectExchange("noQueueExchange");
    }
}
